package logic

import (
	"context"
	"goods-srv/model/mysql"
	"gorm.io/gorm"

	"goods-srv/goods"
	"goods-srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsDetailLogic {
	return &GoodsDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsDetailLogic) GoodsDetail(in *goods.GoodsDetailRequest) (*goods.GoodsDetailResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{
		Model: gorm.Model{ID: uint(in.GoodsId)},
	}
	err := g.FindID()
	if err != nil {
		logx.Error("查询信息失败")
		return nil, err
	}
	return &goods.GoodsDetailResponse{
		GoodsTitle:  g.GoodsTitle,
		GoodsPrice:  g.GoodsPrice,
		GoodsStock:  g.GoodsStock,
		GoodsCover:  g.GoodsCover,
		GoodsStatus: g.GoodsStatus,
		GoodsType:   g.GoodsType,
		ID:          int64(g.ID),
	}, nil
}
